package tianrun.ziguan.api.calculate.config.dto.request.common.add.edit;

import java.util.Map;
import java.util.Objects;

public class SaveBody {

    private Long id;
    private Option option;
    private String tableName;
    private Map<String, Object> data;
    private Map<String, Object> keymap;
    private Map<String, Object> rawData;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Option getOption() {
        return option;
    }

    public void setOption(Option option) {
        this.option = option;
    }

    public String getTableName() {
        return tableName;
    }

    public void setTableName(String tableName) {
        this.tableName = tableName;
    }

    public Map<String, Object> getData() {
        return data;
    }

    public void setData(Map<String, Object> data) {
        this.data = data;
    }

    public Map<String, Object> getKeymap() {
        return keymap;
    }

    public void setKeymap(Map<String, Object> keymap) {
        this.keymap = keymap;
    }

    public Map<String, Object> getRawData() {
        return rawData;
    }

    public void setRawData(Map<String, Object> rawData) {
        this.rawData = rawData;
    }

    public boolean isAdd() {
        return Objects.equals(option,Option.ADD);
    }

    public void keymap(Map<String, Object> keymap) {
        this.setKeymap(keymap);
        this.setId(keymap.isEmpty() ? null : (Long) keymap.values().toArray()[0]);
        this.setOption(keymap.isEmpty() ? SaveBody.Option.ADD : SaveBody.Option.EDIT);
    }

    public enum Option {
        ADD, EDIT
    }
}
